import { ReactNode, useState } from "react";
import { createContext } from 'use-context-selector';
import { useEventEmitter, useRequest } from "ahooks";
import { EventEmitter } from 'ahooks/lib/useEventEmitter';
import { RoleManageEvent } from "@/types/role";

type RoleManageContextType = {
  event$: EventEmitter<RoleManageEvent> | null;
}

export const RoleManageContext = createContext<RoleManageContextType>({
  event$: null,
});

const RoleManageContextProvider = ({ children }: { children: ReactNode }) => {
  const event$ = useEventEmitter<RoleManageEvent>();
  const contextValue: RoleManageContextType = {
    event$
  };

  return (
    <RoleManageContext.Provider value={contextValue}>
      {children}
    </RoleManageContext.Provider>
  );
}

export default RoleManageContextProvider;